<template>
  <div class="subject">
    <span>{{ n1 }}</span>
    <span>+</span>
    <span>{{ n2 }}</span>
    <span>=</span>
    <input type="number" v-model.number="sum" />
    <button @click="submit">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      n1: Math.floor(Math.random() * 10 + 1),
      n2: Math.floor(Math.random() * 10 + 1),
      sum: "",
    };
  },
  methods: {
    submit() {
      if (this.sum === "") return alert("请输入答案");
      this.$emit("submit", this.sum === this.n1 + this.n2, this.item);
    },
  },
  props: {
    item: {
      type: Number,
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>
